const Joi = require('joi');

class InventoryValidate {

  async list(params) {

    const schema = Joi.object({
      name: Joi.string()
        .pattern(/^[^\s]+$/)
        .messages({
          'string.pattern': '名称中不能包含特殊字符',
        }),

      barcode: Joi.string(),
      type: Joi.string(),
      order: Joi.string().default('create_time'),
      method: Joi.string().default('desc'),
      pageIndex: Joi.string().default('1'),
      pageSize: Joi.string().default('10'),
    });

    try {
      const value = await schema.validateAsync(params);
      return value;
    } catch (error) {
      throw error;
    }
  }

}

module.exports = new InventoryValidate();
